using System;
using UnityEngine;

public class InputManager : SingletonMonoBehaviour<InputManager>
{
	private void Update()
	{
		if (Time.timeScale <= 0f)
		{
			return;
		}
		this.UpdateMouseProcess();
		this.UpdateKeyProcess();
	}

	private void UpdateMouseProcess()
	{
		if (UnityEngine.Input.touchCount <= 0)
		{
			return;
		}
		Vector3 lhs = this.mousePosition;
		if (Input.GetMouseButtonDown(0) && !this.buttonDown)
		{
			this.buttonDown = true;
			this.mousePosition = UnityEngine.Input.GetTouch(0).position;
			if (InputManager.onMouseDown != null)
			{
				InputManager.onMouseDown(this.mousePosition);
			}
		}
		if (Input.GetMouseButtonUp(0) && this.buttonDown)
		{
			this.buttonDown = false;
			this.mousePosition = UnityEngine.Input.GetTouch(0).position;
			if (InputManager.onMouseUp != null)
			{
				InputManager.onMouseUp(this.mousePosition);
			}
		}
		if (Input.GetMouseButton(0) && this.buttonDown)
		{
			if (InputManager.onMousePress != null)
			{
				InputManager.onMousePress(this.mousePosition);
			}
			this.mousePosition = UnityEngine.Input.GetTouch(0).position;
			if (lhs != UnityEngine.Input.mousePosition && InputManager.onMouseDrag != null)
			{
				InputManager.onMouseDrag(this.mousePosition);
			}
		}
	}

	private void UpdateKeyProcess()
	{
		if (this.CheckAndroidEscapeKeyState())
		{
			this.ResetAndroidEscapeKeyState();
			if (InputManager.onEscape != null)
			{
				InputManager.onEscape();
			}
		}
	}

	private bool CheckAndroidEscapeKeyState()
	{
		return (Application.platform == RuntimePlatform.Android || Application.isEditor) && UnityEngine.Input.GetKeyUp(KeyCode.Escape) && Time.time - this.timeEscape > InputManager.timeEscapeInterval;
	}

	private void ResetAndroidEscapeKeyState()
	{
		this.timeEscape = Time.time;
	}

	public static Action<Vector3> onMouseDown;

	public static Action<Vector3> onMouseUp;

	public static Action<Vector3> onMousePress;

	public static Action<Vector3> onMouseDrag;

	public static Action onEscape;

	public static float timeEscapeInterval = 0.6f;

	private bool buttonDown;

	private Vector3 mousePosition = Vector3.zero;

	private float timeEscape;
}
